﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using System.Web;

namespace SelfMadeMillionaire.Core
{
    public class LoggingUtility
    {
		private static ILog m_logger = LogManager.GetLogger("ApplicationLogger");

		public void WriteErrorToLog(Exception ex, string additionalInfo = null)
		{
			StringBuilder message = new StringBuilder("Application exception detected");

			if (!string.IsNullOrWhiteSpace(additionalInfo))
				message.Append("\r\n" + additionalInfo);

			for (Exception currentException = ex; currentException != null;
				currentException = currentException.InnerException)
			{
				message.AppendFormat("\r\ntype={0}\r\nmessage={1}\r\nstack=\r\n{2}",
					currentException.GetType().FullName,
					currentException.Message,
					currentException.StackTrace);
			}

			m_logger.Error(message);
		}
        
        public void WriteErrorFormat(string format, params  object[] args)
        {
            m_logger.ErrorFormat(format, args);
        }

    }
}
